﻿using System;
using System.Collections.Generic;
using System.Text;

namespace Kevin.Framework.Validation
{
    [AttributeUsage(AttributeTargets.Property
        | AttributeTargets.Field,
        AllowMultiple = true,
       Inherited = false)]
    public class IntegerRangeValidatorAttribute : ValidatorAttribute
    {
        private int lowerBound;
        private int upperBound;

        /// <summary>
        /// 
        /// </summary>
        public int LowerBound
        {
            get
            {
                return lowerBound;
            }
        }

        /// <summary>
        /// 
        /// </summary>
        public int UpperBound
        {
            get { return upperBound; }
        }

        /// <summary>
        /// IntegerRangeValidatorAttribute构造函数
        /// </summary>
        /// <param name="lowerBound">整形值下限</param>
        /// <param name="upperBound">整形值上限</param>
        public IntegerRangeValidatorAttribute(int lowerBound, int upperBound)
        {
            this.lowerBound = lowerBound;
            this.upperBound = upperBound;
        }

        /// <summary>
        /// 重载基类的方法，调用IntegerRangeValidator的构造方式创建一个IntegerRangeValidator实例
        /// </summary>
        /// <param name="targetType">目标类型，在本默认实现中未使用到该参数</param>
        /// <returns>IntegerRangeValidator实例</returns>
        protected override Validator DoCreateValidator(Type targetType)
        {
            return new IntegerRangeValidator(this.lowerBound, this.upperBound, this.MessageTemplate, this.Tag);
        }
    }
}
